home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BTRVEX.ZIP / ACREATE.C next >
Encoding:
C/C++ Source or Header  |  1989-04-06  |  2.2 KB  |  87 lines

  1. #include <btrvexp.h>
  2. #include <stdio.h>
  3.  
  4. main()
  5. {
  6.    /* Record Buffer for AREACODE.DAT */
  7.    struct
  8.       {
  9.       char state[15];
  10.       char areacode[3];
  11.       char code[2];
  12.       char crlf[2];      /* This is truncated when ADDed */
  13.       } record;
  14.  
  15.  
  16.    int recs,temp;
  17.    FILE *infile;
  18.    STATBUF statbuf;
  19.    char path[80];
  20.  
  21.    BSTART();
  22.    B_OPENMODE = B_ACCELERATED;
  23.  
  24.    statbuf.reclen    =  20 ;
  25.    statbuf.pgsize    = 512 ;
  26.    statbuf.numind    =   3 ;
  27.    statbuf.numrecs   =   0L;
  28.    statbuf.fileflags =   0 ;
  29.  
  30.    statbuf.segment[0].key_pos   =  1;
  31.    statbuf.segment[0].key_len   = 15;
  32.    statbuf.segment[0].key_flags = DUPLICATE | SEGMENTED | ALT_COL_SEQ | EXTENDED;
  33.    statbuf.segment[0].ext_key_type = B_ZSTRING;
  34.  
  35.    statbuf.segment[1].key_pos   = 16;
  36.    statbuf.segment[1].key_len   =  3;
  37.    statbuf.segment[1].key_flags = DUPLICATE;
  38.  
  39.    statbuf.segment[2].key_pos   = 16;
  40.    statbuf.segment[2].key_len   =  3;
  41.    statbuf.segment[2].key_flags =  0;
  42.  
  43.    statbuf.segment[3].key_pos   = 19;
  44.    statbuf.segment[3].key_len   =  2;
  45.    statbuf.segment[3].key_flags =  DUPLICATE | ALT_COL_SEQ;
  46.  
  47.    _searchenv("UPPER.ALT","PATH",path);
  48.    if (path[0] != '\0')
  49.       {
  50.       infile = fopen(path,"rb");
  51.       if ( fread(&statbuf.segment[4],265,1,infile) == 0)
  52.          {
  53.          printf("Could not read UPPER.ALT");
  54.          exit(0);
  55.          }
  56.       fclose(infile);
  57.       }
  58.    else
  59.       {
  60.       printf("Could not find UPPER.ALT\n");
  61.       exit(0);
  62.       }
  63.  
  64.    statbuf.buf_len = 345;   /* (1 * 16 byte header)
  65.                              + (4 * 16 byte segments)
  66.                              + (   265 byte alternate collating sequence) */
  67.  
  68.    BCREATE("areacode.dat",&statbuf);
  69.    infile = fopen("areacode.txt","rb");
  70.    while ( fread(record.state,22,1,infile) != NULL)
  71.       {
  72.       BADD("areacode.dat",&record);
  73.       if (BSTATUS != 0)
  74.          {
  75.          GET_ERR_MSG(BSTATUS);
  76.          printf("Btrieve Error %d on \"%.18s\"\n%s\n\n",errmsg.errnum,&record,errmsg.descrip);
  77.          }
  78.       }
  79.    fclose(infile);
  80.  
  81.    BFILEINFO("areacode.dat",NUM_RECS,&recs);
  82.    printf("\n\nThere are %d records in the file\n\n",recs);
  83.  
  84.    BCLOSE(ALL_FILES);
  85.  
  86. }
  87.